#     2、第二个作业
#         1、写一个产生一批密码的程序，输入100，就产生100条密码
#         2、要求密码长度大于6，必须包含大写字母、小写字母、数字和特殊符号
#         3、每次产生的密码不能重复
#         4、写到文件里面


import random
import string

Lower = []
lower = string.ascii_lowercase
for i in lower:
    Lower.append(i)
Lower1 = set(Lower)

Upper = []
upper= string.ascii_uppercase
for i in upper:
    Upper.append(i)
Upper1 = set(Upper)

Digit = []
digit= string.digits
for i in digit:
    Digit.append(i)
Digit1 = set(Digit)

Punc = []
punc= string.punctuation
for i in punc:
    Punc.append(i)
Punc1 = set(Punc)

Pwd_choice =Lower+Upper+Digit+Punc
number = input('请输入密码个数：')
number = int(number)
all_pwd = []
count = 0

while count < number:
 pwd = random.sample(Pwd_choice,8)
 pwd1 = set(pwd)
 if pwd1.intersection(Lower1)!=set() and pwd1.intersection(Upper1)!=set() and pwd1.intersection(Digit1)!=set() and pwd1.intersection(Punc)!=set() :
    pwd2 = ''.join(pwd)
    if all_pwd.count(pwd2)==0:
          all_pwd.append(pwd2)
          print(pwd2)
          count = count + 1
    else:
        count = count -1
else:
    count = count -1
print(all_pwd)
for i in all_pwd:
    result = i+'\n'
    f = open('psw.txt','a',encoding='UTF-8')
    f.write(result)
    f.close()
